<%@ page import="java.util.List" %>
<%@ page import="com.chg.mymvc.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <link href="css/main.css" rel="stylesheet">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/main.js"></script>

</head>
<body>
<div class="AccountManagement_c " id="AccountManagement_c">
    <h3>账户管理
        <div class="amcl fr">
            <form action="selectuser" method="post" id="formform">
            <input type="text" placeholder="用户名" class="fl" name="getlistbyname" id="getlistbyname">
<%--<button class="search fl"   type="submit"  style="background:url(images/search.png);"></button>--%>
                <div class="search fl">   <img id="imgimg" src="<%=request.getContextPath()%>/images/search.png"  onclick="imgclick()"/></div>
<%--                <input type="text" placeholder="用户名" class="fl"  name="getlistbyname" id="getlistbyname">--%>
<%--              <div class="search fl" type="submit"><img sr="images/search.png"></div>--%>
        </div>
    </h3>
    <div class="AM_ct text_center">
        <div class="AM_ct_in">
            <div class="add_btn df_btn fl" id="add_Account_btn">添加</div>

            <div class="fr df_btn ac_btn" id="ac_Account_btn">账号授权</div>
        </div>
    </div>

    <div class="list">
        <ul class="list_h">
            <li class="b20"><label><input type="checkbox" name=""><span>用户名</span></label></li>
            <li class="b20"><label>密码</label></li>
            <li class="b60"><label>授权形式</label></li>
        </ul>
        <div class="list_b_c">

            <%
                List<User> list = (List<User>) request.getAttribute("list");
                if(list.size()<1){
                        %>
            <ul class="list_null">
                <li class="text_center">未添加管理员账户！</li>
            </ul>
            <%  }  else{%>

            <%
            for(User user:list){
            %>
            <ul class="list_b" style="width:100%">
                <li style="width:10%"><label><span><%=user.getName()%></span></label></li>
                <li style="width:25%"><label><%=user.getPassword()%></label></li>
                <li style="padding-right:50px; width:15%"><label>尚未授权</label></li>
                <li style="text-align: center;width:45%">
                    <div>
                   <button class="edit_btn df_btn fl edit_Account_btn" id="edit_Account_btn"
                           onclick="updateFuction(<%=user.getId()%>,'<%=user.getName()%>','<%=user.getPassword()%>')">
                   编辑
                   </button>
                       <button  class="delete_btn df_btn fl" onclick="abc(<%=user.getId()%>)">删除</button>
                    </div>
                </li>
            </ul>
            <%  }}%>



        </div>
<%--//页数不能是静态的，得是遍历出来的--%>

        <div class="pull_page">
           <a href="amanage.html?pagenum=${page.prePage}"> <div class="fl pull_page_up">上一页</div></a>

            <ul>
            <c:forEach begin="1" end="${page.pages}" var="pag">

                <c:choose>
                <c:when test="${page.pageNum == pag}">
                    <li class="on"><a href="amanage.html?pagenum=${pag}">${pag}</a></li>
                </c:when>
                <c:otherwise>
                    <li ><a href="amanage.html?pagenum=${pag}">${pag}</a></li>
                </c:otherwise>
                </c:choose>
            </c:forEach>
            </ul>
           <a href="amanage.html?pagenum=${page.nextPage}"> <div class="fl pull_page_down">下一页</div></a>
        </div>


    </div>
</div>


<!-- 弹窗 -->
<!-- 添加账户 -->
<div class="add_Account dn" id="add_Account">
    <form action="adduser" method="post" id="user_add_form">

    <div class="add_Account_c">
        <div class="add_Account_h">
            <div class="add_Account_h_in">
                添加账户
                <span class="fr add_Account_close"><img src="images/close.png"></span>
            </div>
        </div>
        <span id="usermsg" style="color: red"></span>
        <div class="user_name user_i">
            <label>用户名</label> <input type="text" placeholder="输入用户名" name="name" id="add_user_ajax" onblur="checkname()"/>
        </div>
        <div class="user_password user_i">
            <label>密<i>调</i>码</label> <input type="password" placeholder="输入密码" name="password">
        </div>
        <input type="submit" class="add_Account_ok_btn text_center" id="add_Account_ok_btn" style="margin-left:35px;margin-top:-5px;" ></input>
    </div>
        </form>
</div>

<!-- 账户编辑 -->
<div class="add_Account dn" id="user_column">
    <form action="updateuser" method="post" >
    <div class="add_Account_c">
       <div class="add_Account_h">
         <div class="add_Account_h_in">
                编辑账户
                <span class="fr add_Account_close"><img src="images/close.png"></span>
            </div>
        </div>
        <div class="column_now ">正在编辑 <span id="spanspan"></span>账户</div>

        <input type="text" name="updateNewId" id="updateNewId" style="display: none">

        <div class="user_name user_i">
            <label>用户名</label>
            <input type="text" placeholder="输入用户名" name="updatename" id="updatename">
        </div>
        <div class="user_password user_i">
            <label>密<i>调</i>码</label>
            <input type="password" placeholder="输入密码" name="updatepassword"  id="updatepassword">
        </div>
<%--        <%--%>
<%--            request.setAttribute("uname",);--%>
<%--            request.setAttribute("upassword",);--%>
<%--        %>--%>
        <input type="submit" class="add_Account_ok_btn text_center" style="margin-left:35px;margin-top:-5px;" ></input>
    </div>
    </form>
</div>

<!-- 删除账户 -->
<div class="add_Account dn" id="delete_Account">
    <form action="deleteuser" method="post" id="user_delete_form">
    <div class="add_Account_c">
        <div class="add_Account_h">
            <div class="add_Account_h_in">
                删除账户
                <span class="fr add_Account_close"><img src="images/close.png"></span>
            </div>
        </div>
        <div class="delete_text">确定删除“ <span>jiaopwuchu</span> ”账户吗？</div>
        <input type="submit" class="add_Account_ok_btn text_center" id="delete_Account_ok_btn">确<i>皮</i>定</input>
    </div>
    </form>
    <div>

<!-- 账户授权 -->
<div class="add_Account dn" id="ac_Account">
    <div class="add_Account_c">
        <div class="add_Account_h">
            <div class="add_Account_h_in">
                账户栏目授权
                <span class="fr add_Account_close"><img src="images/close.png"></span>
            </div>
        </div>
        <ul>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
            <li><label><input type="checkbox" name="">&nbsp;<span>教务处</span></label></li>
        </ul>
        <div class="add_Account_ok_btn text_center" id="ac_Account_ok_btn">保<i>呀</i>存</div>
    </div>
</div>
        <script>
            var updateFuction;   //定义一全局变量
            updateFuction=function update(id,name,password) {
                if (id != null) {
                    $("#updateNewId").val(id);
                    $("#updatename").val(name);
                    $("#updatepassword").val(password);
                    $(".add_Account #spanspan").val(name)

                }
            }

            function  abc(str) {
                if(confirm("确认删除吗")){
                    window.location.href="deleteuser?id="+str;
                }else {
                    return false;
                }

            };

            function checkname() {
                var name=$("#add_user_ajax").val();
                $.ajax({
                    type: "GET",
                    url: "adduserajax?addname="+name,
                    dataType: "text",
                    success : function(data){

                        $("#usermsg").html(data);

                    }
                });
            }


           $("#imgimg").on('click',function(){
               $("#formform").submit();
           })

            // function add_user_ajax(){
            //     var name = document.getElementById("add_user_ajax").value;
            //     // 使用谁来请求XMLHttpRequest对象     请求路径    请求的类型      携带的参数     什么时候成功  响应的内容
            //     var req=new XMLHttpRequest();
            //     req.open("post","adduser")//打开一个请求
            //     req.send();//发送请求
            //     //等待响应
            //     //响应对应五个状态码，每当readyState属性改变时，就会调用该函数      4？？？
            //     req.onreadystatechange=function(){
            //         //获取服务的响应信息     服务器响应就绪   状态码正常
            //
            //         if (req.readyState==4 && req.status==200)
            //         {
            //             var msg = document.getElementById("msg");
            //             if(req.responseText=="ok"){
            //                 msg.innerHTML="<font color='red'>用户名已经存在</font>";
            //             }
            //             else{
            //                 msg.innerHTML="<font color='#7fffd4'>√<font>";
            //             }
            //         }
            //     }
            // }


        </script>
</body>

</html>
